<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>后台管理模板</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
		<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
	</head>
	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
			<!--头部导航-->
			<div class="layui-header header header-demo" ></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side">
			</div>
			<!--右侧具体内容-->
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
				<div class="title">添加管理员</div>
				<hr/>
				<div class="info-content">
					<form class="layui-form" action="manager.html">
						<div class="layui-form-item">
							<img src="../../images/demo1.png" style="margin:20px 20px 20px 50px;width: 60px" id="mhead"><div class="layui-btn layui-btn-radius layui-btn-primary" style="margin:20px 10px">上传头像</div>
						</div>
						<div class="layui-form-item" style="margin-right: 800px">
							<label class="layui-form-label">用户名</label>
							<div class="layui-input-block">
								<input type="text" name="mid" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item" style="margin-right: 800px">
							<label class="layui-form-label">昵称</label>
							<div class="layui-input-block">
								<input type="text" name="mname" required  lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">单选框</label>
							<div class="layui-input-block">
								<input type="radio" name="msex" value="男" title="男">
								<input type="radio" name="msex" value="女" title="女" checked>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">类型</label>
							<div class="layui-input-block">
								<input type="radio" name="manager_type" value="1" title="超级管理员">
								<input type="radio" name="manager_type" value="0" title="普通管理员" checked>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">密码</label>
							<div class="layui-input-inline">
								<input type="password" name="mpassword" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">填写正确信息方可完成信息修改</div>
						</div>
					</form>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="formDemo" id="confirmadd">确认添加</button>
							</div>
						</div>
				</div>
				<!--底部导航-->
				<div class="layui-footer footer footer-demo" id="admin-footer"></div>
				<!--JS模块-->
				<script type="text/javascript" src="../../layui/layui.js"></script>
				<script src="../../js/jquery-1.12.3.min.js"></script>
				<script src="../../js/index.js"></script>
				<script>
				$(document).ready(function()
				{
					alert($("input[ name='mid' ] ").val())
					$("input[ name='mid' ] ").val("")
					$("input[ name='mpassword' ] ").val("")
					$(" input[ name='mname' ] ").val("")
				})
				layui.use('form', function() {
							var form = layui.form();

							$("#confirmadd").on("click", function() 
							{
								addManager()
							})

							function addManager() 
							{
								/*var data = {
										"code": 2
									}*/
									$.ajax(
									{
										url: '/randomdelivery/AdminController/Admin',
										type: 'POST',
										dataType: 'json',
										contentType: "application/json",
										data: JSON.stringify(
										{
											
												"adminName": $("input[ name='mid' ] ").val(),
												"adminPwd": $("input[ name='mpassword' ] ").val(),
												"adminNickname": $(" input[ name='mname' ] ").val(),
												"adminSex": $(" input[ name='msex' ] ").val(),
												"adminPower": $(" input[ name='manager_type' ] ").val(),
												"adminUrl": $("#mhead").src,
												"adminState": 1
											
										}),
										success: function(data) 
										{
											ifaddDone(data)
										},
										error: function() 
										{
											alert("服务器出错");
										}
									});

								function ifaddDone(data) {
									if (data.code == 200) {
										alert("添加成功")
										window.location.href = "manager.html";
									}
								}
							}
								//各种基于事件的操作，下面会有进一步介绍
								// form.render();
							});
				</script>
			</div>
		</div>
	</body>
</html>